package com.sds.sweng.swat.miplatform.ui.design.figures.logical;

import org.apache.commons.lang.StringUtils;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.jface.resource.ImageDescriptor;

import com.sds.sweng.swat.miplatform.ui.design.figures.MLabel;
import com.sds.sweng.swat.miplatform.ui.design.utils.FontUtils;

public class LRadioButtonFigure extends MLabel {

	private String text = StringUtils.EMPTY;

	public LRadioButtonFigure() {
		setBorder(new LineBorder(ColorConstants.lightGray, 1, Graphics.LINE_DASH));
		setFont(FontUtils.DEFAULT_FONT);
	}

	public void setText(String text) {
		this.text = text;
	}

	protected void paintFigure(Graphics graphics) {
		super.paintFigure(graphics);

		int x = bounds.x+1;
		int y = bounds.y;

		String[] items = StringUtils.split(text, ";");

		for (int i=0;i<items.length;i++) {
			if (i == 0)
				graphics.drawImage(ImageDescriptor.createFromFile(getClass(), "images/radio_selected.gif").createImage(), x, y+(bounds.height/2)-6);
			else
				graphics.drawImage(ImageDescriptor.createFromFile(getClass(), "images/radio.gif").createImage(), x, y+(bounds.height/2)-6);
			graphics.drawText(items[i], x+17, y+4);

			x += FontUtils.getTextWidth(items[i]) + 29;
		}
	}

}
